package com.jxtc.enterprise.employee.vo;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.jxtc.enterprise.common.entity.ShoppingCart;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@Schema(description = "微信端购物车详情数据")
@Getter
@Setter
@ToString
@NoArgsConstructor
public class ShoppingCartVO {

    @Schema(description = "购物车 ID")
    private String shoppingCartId;

    @Schema(description = "菜品 ID")
    private String foodId;

    @Schema(description = "菜品名称")
    private String foodName;

    @Schema(description = "店铺 ID")
    private String storeId;

    @Schema(description = "店铺名称")
    private String storeName;

    @Schema(description = "菜品规格")
    private JSONArray specifications;

    @Schema(description = "菜品数量")
    private Integer count;

    @Schema(description = "菜品图片")
    private String foodImage;

    @Schema(description = "菜品价格")
    private Integer foodPrice;

    @Schema(description = "菜品展示价格")
    private Integer showPrice;

    @Schema(description = "菜品总价格")
    private Integer totalPrice;

    public Double getTotalPrice() {
        return totalPrice / 100.0;
    }

    public Double getFoodPrice() {
        return foodPrice / 100.0;
    }

    public Double getShowPrice() {
        return showPrice / 100.0;
    }

    public ShoppingCartVO(ShoppingCart shoppingCart) {
        this.shoppingCartId = shoppingCart.getId();
        this.foodId = shoppingCart.getFoodId();
        this.foodName = shoppingCart.getFoodName();
        this.storeId = shoppingCart.getStoreId();
        this.storeName = shoppingCart.getStoreName();
        this.specifications = JSONUtil.parseArray(shoppingCart.getSpecification());
        this.count = shoppingCart.getCount();
        this.foodImage = shoppingCart.getFoodImage();
        this.foodPrice = shoppingCart.getSalePrice() / this.count;
        this.showPrice = shoppingCart.getShowPrice();
        this.totalPrice = shoppingCart.getSalePrice();
    }
}
